# Build script for file.
#
# Copyright (c) 2014-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

version=5.41

cd -- "$TMPDIR"
rm -rf file-${version}
unpack "${worktree}/sources/file-${version}.tar.gz"

# Build instructions
cd file-${version}

# A local installation of "file" is needed in order
# to cross-compile "file" matching the same version
./configure \
 --prefix="$crossdir" \
 --disable-fsect-man5

make -j1 V=1
make -j1 install

make -j1 clean

# Import and export toolchain variables
. "${worktree}/stages/env.d/cross-staticenv"

./configure \
AR="$AR" AS="$AS" LD="$LD" RANLIB="$RANLIB" READELF="$READELF" STRIP="$STRIP" \
CC="$BTCC" CXX="$BTCXX" \
CFLAGS="$BTCFLAGS" CXXFLAGS="$BTCXXFLAGS" LDFLAGS="$BTLDFLAGS" \
 --prefix=/tools \
 --build=$host \
 --host=$target \
 --disable-fsect-man5

make -j1 V=1
make -j1 install

# Unset some imported variables from file
unset AR AS LD RANLIB READELF STRIP

cleanup()
{
    cd -- "$TMPDIR" && rm -rf file-${version}
}

